import axios from "axios";
import store from "@/store";
const instance = axios.create({
    baseURL: "http://kumanxuan1.f3322.net:8881/cms",
    // baseURL:"",
    timeout: 5000
})

instance.interceptors.request.use(config => {
    console.log("config为",config);
    let token =localStorage.getItem("x-auth-token");
    if(token){
        config.headers["x-auth-token"]=token
    }
    return config
}, err => {
    
    return Promise.reject(err)
})

instance.interceptors.response.use(res => { 
    let res_data=res.data
    if(res_data.code!=0){
        store.dispatch("toastStatus/asyncchangeIsShowToast",{
            msg:res_data.message,
            type:"err"
        })
        return false
    }
    return res_data
}, err => {
    store.dispatch("toastStatus/asyncchangeIsShowToast",{
        msg:err,
        type:"err"
    })
    return Promise.reject(err)

})



export default instance